﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CRMAdminDashboard.CrmSvc;

namespace CRMAdminDashboard
{
    /// <summary>
    /// Serializable version of SystemUser
    /// </summary>
    [Serializable]
    public class SerializableUser : systemuser
    {

        #region Properties

        public List<SerializableRole> Roles { get; set; }

        #endregion

        #region Entry Points

        /// <summary>
        /// Make a serializable user out of SystemUser. Include related roles.
        /// </summary>
        public SerializableUser(CachingCrmService svcHandle, SystemUser suser)
            : this(suser)
        {
            Dictionary<Guid, SystemRole> roles = suser.GetRoles(svcHandle, new AllColumns());
            this.Roles = new List<SerializableRole>();
            foreach (SystemRole role in roles.Values)
            {
                this.Roles.Add(new SerializableRole(role));
            }
        }

        /// <summary>
        /// Make a serializable user out of SystemUser
        /// </summary>
        public SerializableUser(SystemUser suser)
        {
            this.accessmode = suser.InnerUser.accessmode;
            this.address1_addressid = suser.InnerUser.address1_addressid;
            this.address1_addresstypecode = suser.InnerUser.address1_addresstypecode;
            this.address1_city = suser.InnerUser.address1_city;
            this.address1_country = suser.InnerUser.address1_country;
            this.address1_county = suser.InnerUser.address1_county;
            this.address1_fax = suser.InnerUser.address1_fax;
            this.address1_latitude = suser.InnerUser.address1_latitude;
            this.address1_line1 = suser.InnerUser.address1_line1;
            this.address1_line2 = suser.InnerUser.address1_line2;
            this.address1_line3 = suser.InnerUser.address1_line3;
            this.address1_longitude = suser.InnerUser.address1_longitude;
            this.address1_name = suser.InnerUser.address1_name;
            this.address1_postalcode = suser.InnerUser.address1_postalcode;
            this.address1_postofficebox = suser.InnerUser.address1_postofficebox;
            this.address1_shippingmethodcode = suser.InnerUser.address1_shippingmethodcode;
            this.address1_stateorprovince = suser.InnerUser.address1_stateorprovince;
            this.address1_telephone1 = suser.InnerUser.address1_telephone1;
            this.address1_telephone2 = suser.InnerUser.address1_telephone2;
            this.address1_telephone3 = suser.InnerUser.address1_telephone3;
            this.address1_upszone = suser.InnerUser.address1_upszone;
            this.address1_utcoffset = suser.InnerUser.address1_utcoffset;
            this.address2_addressid = suser.InnerUser.address2_addressid;
            this.address2_addresstypecode = suser.InnerUser.address2_addresstypecode;
            this.address2_city = suser.InnerUser.address2_city;
            this.address2_country = suser.InnerUser.address2_country;
            this.address2_county = suser.InnerUser.address2_county;
            this.address2_fax = suser.InnerUser.address2_fax;
            this.address2_latitude = suser.InnerUser.address2_latitude;
            this.address2_line1 = suser.InnerUser.address2_line1;
            this.address2_line2 = suser.InnerUser.address2_line2;
            this.address2_line3 = suser.InnerUser.address2_line3;
            this.address2_longitude = suser.InnerUser.address2_longitude;
            this.address2_name = suser.InnerUser.address2_name;
            this.address2_postalcode = suser.InnerUser.address2_postalcode;
            this.address2_postofficebox = suser.InnerUser.address2_postofficebox;
            this.address2_shippingmethodcode = suser.InnerUser.address2_shippingmethodcode;
            this.address2_stateorprovince = suser.InnerUser.address2_stateorprovince;
            this.address2_telephone1 = suser.InnerUser.address2_telephone1;
            this.address2_telephone2 = suser.InnerUser.address2_telephone2;
            this.address2_telephone3 = suser.InnerUser.address2_telephone3;
            this.address2_upszone = suser.InnerUser.address2_upszone;
            this.address2_utcoffset = suser.InnerUser.address2_utcoffset;
            this.businessunitid = suser.InnerUser.businessunitid;
            this.calendarid = suser.InnerUser.calendarid;
            this.createdby = suser.InnerUser.createdby;
            this.createdon = suser.InnerUser.createdon;
            this.disabledreason = suser.InnerUser.disabledreason;
            this.displayinserviceviews = suser.InnerUser.displayinserviceviews;
            this.domainname = suser.InnerUser.domainname;
            this.employeeid = suser.InnerUser.employeeid;
            this.firstname = suser.InnerUser.firstname;
            this.fullname = suser.InnerUser.fullname;
            this.governmentid = suser.InnerUser.governmentid;
            this.homephone = suser.InnerUser.homephone;
            this.importsequencenumber = suser.InnerUser.importsequencenumber;
            this.incomingemaildeliverymethod = suser.InnerUser.incomingemaildeliverymethod;
            this.internalemailaddress = suser.InnerUser.internalemailaddress;
            this.invitestatuscode = suser.InnerUser.invitestatuscode;
            this.isdisabled = suser.InnerUser.isdisabled;
            this.jobtitle = suser.InnerUser.jobtitle;
            this.lastname = suser.InnerUser.lastname;
            this.middlename = suser.InnerUser.middlename;
            this.mobilealertemail = suser.InnerUser.mobilealertemail;
            this.mobilephone = suser.InnerUser.mobilephone;
            this.modifiedby = suser.InnerUser.modifiedby;
            this.modifiedon = suser.InnerUser.modifiedon;
            this.nickname = suser.InnerUser.nickname;
            this.organizationid = suser.InnerUser.organizationid;
            this.outgoingemaildeliverymethod = suser.InnerUser.outgoingemaildeliverymethod;
            this.overriddencreatedon = suser.InnerUser.overriddencreatedon;
            this.parentsystemuserid = suser.InnerUser.parentsystemuserid;
            this.passporthi = suser.InnerUser.passporthi;
            this.passportlo = suser.InnerUser.passportlo;
            this.personalemailaddress = suser.InnerUser.personalemailaddress;
            this.photourl = suser.InnerUser.photourl;
            this.preferredaddresscode = suser.InnerUser.preferredaddresscode;
            this.preferredemailcode = suser.InnerUser.preferredemailcode;
            this.preferredphonecode = suser.InnerUser.preferredphonecode;
            this.salutation = suser.InnerUser.salutation;
            this.setupuser = suser.InnerUser.setupuser;
            this.siteid = suser.InnerUser.siteid;
            this.skills = suser.InnerUser.skills;
            this.systemuserid = suser.InnerUser.systemuserid;
            this.territoryid = suser.InnerUser.territoryid;
            this.timezoneruleversionnumber = suser.InnerUser.timezoneruleversionnumber;
            this.title = suser.InnerUser.title;
            this.utcconversiontimezonecode = suser.InnerUser.utcconversiontimezonecode;
            this.windowsliveid = suser.InnerUser.windowsliveid;
            this.yomifirstname = suser.InnerUser.yomifirstname;
            this.yomifullname = suser.InnerUser.yomifullname;
            this.yomilastname = suser.InnerUser.yomilastname;
            this.yomimiddlename = suser.InnerUser.yomimiddlename;
        }

        /// <summary>
        /// Needed for the serializer
        /// </summary>
        public SerializableUser() { }

        #endregion

    }
}
